<template>
  <div class="home">
    <div class="my-header">
      <div class="inner">
        <h1>TODOLIST</h1>
        <input type="text" v-model="title" @keydown.13="add" />
      </div>
    </div>
    <!-- 头部 -->

    <ul class="con">
      <h1>正在进行</h1>
      <li
        v-for="(item, index) in list"
        v-show="item.status == false"
        :key="index"
      >
        <!-- 筛选 循环所有的列表 加上v-show 来规定显示谁不显示谁 -->
        <input type="checkbox" v-model="item.status" />
        <!-- 状态这里用v-model双向绑定 视图变 数据也变 -->
        <p>{{ item.title }}</p>
        <span @click="remove(index)">x</span>
      </li>
    </ul>
    <!-- 正在进行的列表 -->

    <ul class="con">
      <h1>已经完成</h1>
      <li
        v-for="(item, index) in list"
        v-show="item.status == true"
        :key="index"
      >
        <input type="checkbox" v-model="item.status" />
        <p>{{ item.title }}</p>
        <span @click="remove(index)">x</span>
      </li>
    </ul>
    <!-- 已经完成的列表 -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [
        { title: "吃饭", status: false },
        { title: "睡觉", status: true },
        { title: "打王者", status: true },
      ],
      //数据应该有一个标题 还应该有一个状态
      title: "",
    };
  },
  methods: {
    add() {
      this.list.push({
        title: this.title,
        status: false,
      });
    },
    remove(index) {
      this.list.splice(index, 1);
    },
  },
};
</script>
<style lang="scss">
.my-header {
  width: 100%;
  height: 50px;
  background: #3c3c3c;
  .inner {
    width: 800px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    input {
      width: 60%;
      height: 30px;
      border-radius: 5px;
      color: #000;
    }
  }
}
.con {
  width: 800px;
  margin: 0 auto;
  li {
    height: 50px;
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
  }
}
</style>
